
/*=========================================
* Author: Administrator
* DateTime:2017/6/20 18:17:21
* Description:$safeprojectname$
==========================================*/

using PureMVC.Interfaces;
using PureMVC.Patterns;
using System;
using UnityEngine;

namespace OrderSystem
{
    /// <summary>
    /// 订单系统外观类，继承自PureMVC的Facade
    /// 负责初始化应用程序、注册核心命令和协调MVC组件
    /// </summary>
    public class ApplicationFacade : Facade
    {
        public ApplicationFacade(FacadeType facadeType) : base(facadeType)
        {

        }

        /// <summary>
        /// 单例实例属性
        /// 提供订单系统唯一的外观实例
        /// </summary>
        public new static IFacade Instance
        {
            get
            {
                if (null == m_instance)
                {
                    lock (m_staticSyncRoot)
                    {
                        if (null == m_instance)
                        {
                            Debug.Log("构造Facade,此处会自动构造View、Controller和Model");
                            m_instance = new ApplicationFacade(facadeType);
                        }
                    }
                }
                return m_instance;
            }
        }

        /// <summary>
        /// 启动应用程序
        /// 发送启动通知，触发StartUpCommand执行
        /// </summary>
        /// <param name="mainUI">主UI实例，作为启动参数传递</param>
        public void StartUp(MainUI mainUI)
        {
            Debug.Log("启动程序"); //mvc，和命令都已经创建好了，
            SendNotification(OrderSystemEvent.STARTUP, mainUI);  //发送启动游戏
        }
        internal void StartUpJob1(Job1MainUI job1MainUI)
        {
            Debug.Log("启动程序"); //mvc，和命令都已经创建好了，
            SendNotification(OrderSystemEvent.STARTUP, job1MainUI);  //发送启动游戏
        }


        #region 重新核心类型的构造方法

        /// <summary>
        /// 重写初始化外观方法
        /// 调用基类初始化并可添加自定义初始化逻辑
        /// </summary>
        protected override void InitializeFacade()
        {
            base.InitializeFacade();
        }

        /// <summary>
        /// 重写初始化视图方法
        /// 可添加订单系统特定的视图初始化逻辑
        /// </summary>
        protected override void InitializeView()
        {
            base.InitializeView();
        }

        /// <summary>
        /// 重写初始化控制器方法
        /// 注册订单系统核心命令（如启动命令）
        /// </summary>
        protected override void InitializeController()
        {
            base.InitializeController();
            switch (facadeType)
            {
                case FacadeType.Pmvc:
                    RegisterCommand(OrderSystemEvent.STARTUP, typeof(StartUpCommand)); //注册启动的事件，注册是命令
                    break;
                case FacadeType.Battle:
                    RegisterCommand(OrderSystemEvent.STARTUP, typeof(Job1StatrUpCommed)); //注册启动的事件，注册是命令
                    break;
            }
        }

        /// <summary>
        /// 重写初始化模型方法
        /// 可添加订单系统特定的数据模型初始化逻辑
        /// </summary>
        protected override void InitializeModel()
        {
            base.InitializeModel();
        }

     
        #endregion
    }
}